import { useContext, useState } from 'react';
import { useDescriptionsType } from '@/components/DescriptionsType';
import { ApplyControllerContext } from '../common';
import { ApplyManageAPI } from '../common/type';
import { DictionaryService } from '../services/DictionaryService';
import { getCompanyID } from '@/utils';
import { findValueFun, renderFileFunc } from '@/common';
import { KYFW_Type, KYWZ_Type, PURCHASE_Type, ZNGL_Type } from '../common/Format';

const getDescrConfig = ({ updateForm, isShowUpload, isShowObj }: ApplyManageAPI.IUpdateDesConfig) => {
  /** 获取上下文 */
  const { pageType, applyForm, applyDetailInfo } = useContext(ApplyControllerContext);
  /**采购办法*/
  const { supplyWayList } = DictionaryService();
  /** 表单配置 */
  const [config, methods] = useDescriptionsType({
    labelWidth: 240,
    basicForm: updateForm ? updateForm : applyForm,
    isShowNumTitle: false,
    name: 'apply-addAndEdit',
    schemas: [
      {
        key: 'applyInfoDesType',
        title: '信息确认',
        fieldChildren: [
          {
            label: '申请日期',
            field: 'applyTime',
            component: 'Input',
            placeholder: '自动带出',
            disabled: true,
          },
          {
            label: '流水单号',
            field: 'applyCode',
            component: 'Input',
            disabled: true,
            placeholder: '自动带出',
          },
          {
            label: '申请人',
            field: 'applyerName',
            component: 'Input',
            disabled: true,
            placeholder: '自动带出',
          },
          {
            label: '联系方式',
            field: 'contactMobile',
            component: 'Input',
            disabled: true,
            placeholder: '自动带出',
          },
          {
            label: '申请部门/单位',
            field: 'applyDepartmentName',
            component: 'Input',
            disabled: true,
            placeholder: '自动带出',
          },
          {
            label: '职务岗位',
            field: 'applyPositionName',
            component: 'Input',
            placeholder: '自动带出',
            disabled: true,
          },
          {
            label: '采购项目名称',
            field: 'applyTitle',
            component: 'Input',
            disabled: true,
            placeholder: '自动带出',
            colSpan: 2,
          },
          {
            label: '采购类别',
            field: 'purchCategory',
            component: 'Render',
            disabled: true,
            colSpan: 1,
            render: (text = 0, record) => {
              return <span>{findValueFun(PURCHASE_Type, text)}</span>;
            },
          },
          {
            label: '采购内容',
            field: 'purchContent',
            component: 'Render',
            disabled: true,
            colSpan: 1,
            render: (text = 0, record) => {
              return (
                <span>
                  {record?.purchCategory == 0
                    ? findValueFun(KYWZ_Type, text)
                    : record?.purchCategory == 1
                    ? findValueFun(KYFW_Type, text)
                    : record?.purchCategory == 2
                    ? findValueFun(ZNGL_Type, text)
                    : '--'}
                </span>
              );
            },
          },
          {
            label: '其他内容',
            field: 'otherContent',
            component: 'InputTextArea',
            disabled: true,
            colSpan: 2,
            ishidden: isShowObj?.isShowOther == 3 ? false : true,
            placeholder: '--',
            // required: true,
            showCount: true,
            allowClear: true,
            maxLength: 200,
            autoSize: { minRows: 4, maxRows: 6 },
          },
          {
            label: '是否共性',
            field: 'commonFlag',
            component: 'Render',
            colSpan: isShowObj?.isShowCommon == 0 ? 2 : 1,
            ishidden: isShowObj?.isShowCategory == 1 || isShowObj?.isShowCategory == 2 ? true : false,
            slotRender: (text: any = 0) => {
              return <span style={{ marginLeft: '8px' }}>{text == 0 ? '否' : text == 1 ? '是' : '--'}</span>;
            },
          },
          {
            label: '实验室业务归口部门',
            field: 'commonDepartmentName',
            component: 'Input',
            placeholder: '--',
            colSpan: isShowObj?.isShowCommon == 0 ? 2 : 1,
            ishidden: isShowObj?.isShowCommon == 0 ? true : isShowObj?.isShowCategory == 1 || isShowObj?.isShowCategory == 2 ? true : false,
            // required: true,
            disabled: true,
          },
          {
            label: '是否平台',
            field: 'platformFlag',
            component: 'Render',
            colSpan: isShowObj?.isShowPlatform == 0 ? 2 : 1,
            slotRender: (text: any = 0) => {
              return <span style={{ marginLeft: '8px' }}>{text == 0 ? '否' : text == 1 ? '是' : '--'}</span>;
            },
          },
          {
            label: '平台归口部门',
            field: 'platformDepartmentName',
            component: 'Input',
            placeholder: '--',
            colSpan: isShowObj?.isShowPlatform == 0 ? 2 : 1,
            ishidden: isShowObj?.isShowPlatform == 0 ? true : false,
            // required: true,
            disabled: true,
          },
          {
            label: '是否会签',
            field: 'consignFlag',
            component: 'Render',
            colSpan: isShowObj?.isShowConsign == 0 ? 2 : 1,
            ishidden: isShowObj?.isShowCategory == 0 || isShowObj?.isShowCategory == 1 ? true : false,
            slotRender: (text: any = 0) => {
              return <span style={{ marginLeft: '8px' }}>{text == 0 ? '否' : text == 1 ? '是' : '--'}</span>;
            },
          },
          {
            label: '实验室会签部门',
            field: 'consignDepartmentName',
            component: 'Input',
            placeholder: '--',
            colSpan: isShowObj?.isShowConsign == 0 ? 2 : 1,
            ishidden: isShowObj?.isShowConsign == 0 ? true : isShowObj?.isShowCategory == 0 || isShowObj?.isShowCategory == 1 ? true : false,
            disabled: true,
          },
          {
            label: '是否上会',
            field: 'meetingFlag',
            component: 'Render',
            colSpan: isShowObj?.isShowMeeting == 0 ? 2 : 1,
            ishidden: isShowObj?.isShowCategory == 0 || isShowObj?.isShowCategory == 1 ? true : false,
            slotRender: (text: any = 0) => {
              return <span style={{ marginLeft: '8px' }}>{text == 0 ? '否' : text == 1 ? '是' : '--'}</span>;
            },
          },
          {
            label: '会议纪要',
            field: 'meetingSummaryUrl',
            placeholder: '请上传会议纪要',
            component: 'Render',
            colSpan: isShowObj?.isShowMeeting == 0 ? 2 : 1,
            ishidden: isShowObj?.isShowMeeting == 0 ? true : isShowObj?.isShowCategory == 0 || isShowObj?.isShowCategory == 1 ? true : false,
            slotRender: (text, record) => {
              return (
                <span style={{ marginLeft: 8 }}>
                  {renderFileFunc({
                    record: applyDetailInfo,
                    fileName: 'meetingSummaryUrl',
                    downloadAddress: '/purchaseApplyController/downloadFile',
                    returnStr: '/',
                  })}
                </span>
              );
            },
          },
          {
            label: '标的来源',
            field: 'supplyWay',
            component: 'Input',
            disabled: true,
            placeholder: '自动带出',
            colSpan: 2,
            render: (text) => {
              let word: any = <span style={{ color: '#bfc0c1' }}>自动带出</span>;
              if (typeof text != 'undefined') {
                word =
                  supplyWayList?.filter((item) => {
                    return item?.value == (text as any);
                  })?.[0]?.name ?? word;
              }
              return <span>{word}</span>;
            },
          },
          {
            label: '预算金额',
            field: 'expectSum',
            component: 'Input',
            placeholder: '自动带出',
            disabled: true,
            colSpan: 2,
            contentAfter: '元',
          },
          {
            label: '采购理由',
            field: 'applyInfo',
            component: 'InputTextArea',
            placeholder: '自动带出',
            disabled: true,
            showCount: true,
            allowClear: true,
            maxLength: 200,
            autoSize: { minRows: 4, maxRows: 6 },
            colSpan: 2,
          },
        ],
      },
    ],
  });

  return {
    config,
    methods,
  };
};

export { getDescrConfig };
